package cz.muni.fi.pa165.musiclibrary.musiclibraryweb;

import org.apache.wicket.protocol.http.WebSession;
import org.apache.wicket.request.Request;

import cz.muni.fi.pa165.musiclibrary.api.service.auth.IUser;

/**
 *
 * @author Maros Kucbel
 * @date 2013-01-26T12:26:40+0100
 */
public final class MusicLibrarySession extends WebSession {

    private IUser user;
    
    public MusicLibrarySession(final Request request) {
        super(request);
    }

    /**
     * @return Logged in user.
     */
    public IUser getUser() {
        return this.user;
    }

    /**
     * Sets logged user.
     * @param user Logged in user.
     */
    public void setUser(IUser user) {
        this.user = user;
    }
    
    /**
     * Checks whether the user is authorized.
     * @return {@code true} id user is authorized, {@code false} otherwise.
     */
    public boolean isAuthorized() {
        return this.getUser() != null;
    }
    
    public static MusicLibrarySession get() {
        return (MusicLibrarySession) WebSession.get();
    }
    
}